import type { ProxyOptions } from "vite";
import { PROXY_DEV_URL } from "./config"

export const createProxy = (env): Record<string, ProxyOptions> => {
  const { VITE_API_BASE_URL } = env
  return {
    '/token': {
      target: PROXY_DEV_URL,
      changeOrigin: true,
      rewrite: (path) => path.replace(/^\/token/, '/token')
    },
    [VITE_API_BASE_URL]: {
      target: PROXY_DEV_URL,
      changeOrigin: true,
      rewrite: (path) => path.replace(new RegExp(`^${VITE_API_BASE_URL}`), '')
    }
  }
}